/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package com.aroundj2me.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import com.aroundj2me.controller.ApplicationController;
import com.aroundj2me.controller.ScreenController;
/**
 * View displaying Comments
 *
 */
public class CommentView extends Form implements CommandListener {
	private ApplicationController controller;
	private TextField commentField;
	private final int MAX_LENGTH = 200;
	
	private Command submit;
	
	public CommentView(ApplicationController controller) {
		super("Comment");
		this.controller = controller;
		createCommands();
		initialize();
		this.setCommandListener(this);
	}
	
	/**
	 * Creates the commands
	 *
	 */
	private void createCommands() {
		submit = new Command("submit", "submit comment", Command.SCREEN, 0);
		
		this.addCommand(submit);
	}

	/**
	 * Initializes the visual components
	 *
	 */
	private void initialize(){
		String item = new String("Leave a comment...");
		commentField = new TextField("Comment:",null, MAX_LENGTH, 0);
		this.append(item);
		this.append(commentField);
	}

	/**
	 * Action handler
	 */
	public void commandAction(Command c, Displayable d) {
		if(c.getCommandType() == Command.BACK){
			ScreenController.getInstance().last();
		}else if(c == submit){
			controller.submitComment();
		}
	}

	/*
	 * Getters and Setters
	 */
	
	public TextField getCommentField() {
		return commentField;
	}

}
